#include "../include/time_capture.h"

std::string AllNowTimeStr()
{
	struct tm t;
	time_t now;
	time(&now);
	localtime_s(&t, &now);

	int year_i = t.tm_year + 1900;
	int month_i = t.tm_mon + 1;
	int day_i = t.tm_mday;
	int hour_i = t.tm_hour;
	int minute_i = t.tm_min;
	int second_i = t.tm_sec;

	std::stringstream sstime;
	sstime << "Year" << year_i << "-Month" << month_i << "-Day" << day_i << "-Hour" << hour_i << "-Minute" << minute_i << "-Second" << second_i;
	return sstime.str();
}


int NowYearInt()
{
	struct tm t;
	time_t now;
	time(&now);
	localtime_s(&t, &now);
	int year_i = t.tm_year + 1900;

	return  year_i;
}

int NowMonthInt()
{
	struct tm t;
	time_t now;
	time(&now);
	localtime_s(&t, &now);
	int month_i = t.tm_mon + 1;

	return month_i;
}

int NowDayInt()
{
	struct tm t;
	time_t now;
	time(&now);
	localtime_s(&t, &now);
	int day_i = t.tm_mday;

	return day_i;
}

int NowHourInt()
{
	struct tm t;
	time_t now;
	time(&now);
	localtime_s(&t, &now);
	int hour_i = t.tm_hour;

	return hour_i;
}

int NowMinuteInt()
{
	struct tm t;
	time_t now;
	time(&now);
	localtime_s(&t, &now);
	int minute_i = t.tm_min;

	return minute_i;
}

int NowSecondInt()
{
	struct tm t;
	time_t now;
	time(&now);
	localtime_s(&t, &now);
	int second_i = t.tm_sec;

	return second_i;
}

dateData NowDate()
{
	dateData temp_date;
	temp_date.Day = NowDayInt();
	temp_date.Month = NowMonthInt();
	temp_date.Year = NowYearInt();
	return temp_date;
}

bool isLeapYear(int Year)
{
	if (Year % 100 == 0)
	{
		if (Year % 400 == 0)
		{
			return true;
		}
	}
	else
	{
		if (Year % 4 == 0)
		{
			return true;
		}
	}
	return false;
}

int getDayTotalNum(int Year, int Month)
{
	int total_day = 0;
	if (Month == 1 ||
		Month == 3 ||
		Month == 5 ||
		Month == 7 ||
		Month == 8 ||
		Month == 10 ||
		Month == 12)
	{
		total_day = 31;
	}
	else if (Month == 2)
	{
		if (isLeapYear(Year))
			total_day = 29;
		else
			total_day = 28;
	}
	else
	{
		total_day = 30;
	}

	return total_day;
}

StampStruct NowStamp()
{
	StampStruct now_stamp;
	now_stamp.Year = NowYearInt();
	now_stamp.Month = NowMonthInt();
	now_stamp.Day = NowDayInt();
	now_stamp.Hour = NowHourInt();
	now_stamp.Minute = NowMinuteInt();
	now_stamp.Second = NowSecondInt();

	return now_stamp;
}